package
{
	import flash.events.*;
	import flash.net.*;
	import flash.text.TextField;
	import flash.utils.getTimer;
	
	public class uLoader
	{
		private var start:uint;
		private var urlResult:TextField;
		
		public function uLoader(req:String,loadtime:TextField )
		{
			urlResult = loadtime;
			
			// Call appengine get
			var loader:URLLoader = new URLLoader();
			configureListeners(loader);
			
			start = getTimer();
			var request:URLRequest = new URLRequest(req);
			try {
				loader.load(request);
			} catch (error:Error) {
				trace("Unable to load requested document.");
			}		
		}// ctor
		
		private function configureListeners(dispatcher:IEventDispatcher):void {
			dispatcher.addEventListener(Event.COMPLETE, completeHandler);
			dispatcher.addEventListener(Event.OPEN, openHandler);
			dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
			dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
			dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
			dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
		}
		
		private function completeHandler(event:Event):void {
			var loader:URLLoader = URLLoader(event.target);
			trace("completeHandler: " + loader.data);
			urlResult.text = ("completed in " + (getTimer()-start).toString() + " ms");			
		}
		
		private function openHandler(event:Event):void {
			urlResult.text = ("openHandler: " + event);
		}
		
		private function progressHandler(event:ProgressEvent):void {
			urlResult.text = ("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
		}
		
		private function securityErrorHandler(event:SecurityErrorEvent):void {
			urlResult.text = ("securityErrorHandler: " + event);
		}
		
		private function httpStatusHandler(event:HTTPStatusEvent):void {
			urlResult.text = ("httpStatusHandler: " + event);
		}
		
		private function ioErrorHandler(event:IOErrorEvent):void {
			urlResult.text = ("ioErrorHandler: " + event);
		}		
	}// class
}// package